//
//  main.cpp
//  一元运算符
//
//  Created by linjinzhu on 2017/7/12.
//  Copyright © 2017年 linjinzhu. All rights reserved.
//

#include <iostream>

using namespace std;

class Distance {
private:
    int feet;
    int inches;

public:
    void displayDistance() {
        cout << "F:" << feet << "\tI:" << inches << endl;
    }
    Distance() {
        feet = inches = 0;
    }
    Distance(int f, int i) {
        feet = f;
        inches = i;
    }

    // 一元运算符重载：重载-号运算符
    Distance operator-() {
        feet = -feet;
        inches = - inches;
        return Distance(feet, inches);
    }

    // 二元运算符重载
    Distance operator+(const Distance &d) {
        Distance dis;
        dis.feet = this->feet + d.feet;
        dis.inches = this->inches + d.inches;

        return dis;
    }

    // 关系运算符
    bool operator<(const Distance &d) {
        if (this->feet < d.feet) {
            return true;
        }

        if (this->feet == d.feet && this->inches < d.inches) {
            return true;
        }

        return false;
    }

    // 输入输出运算符
    friend ostream &operator<<(ostream &output, const Distance &d) {
        output << "F:" << d.feet << "\tI:" << d.inches << endl;
        return output;
    }

    friend istream &operator>>(istream &input, Distance &d) {
        input >> d.feet >> d.inches;
        return input;
    }

};

int main(int argc, const char * argv[]) {

    Distance D1(1, 2);
    Distance D2(3, 5);

    // 一元运算符
    D1.displayDistance();
    D1 = -D1;
    D1.displayDistance();
    D1 = -D1;

    // 二元运算符
    Distance D3 = D1 + D2;

    D3.displayDistance();

    // 关系运算
    cout << (D1 < D3) << endl;

    cout << D1 << endl;
    cin >> D3;
    cout << D3 << endl;


    return 0;
}
